package com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.rule;

import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.BasicRule;
import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.context.UserPortrait;
import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.context.UserPortraitRuleContext;
import org.springframework.stereotype.Component;

/**
 * @author zhouliang
 * @date 2021/1/23 15:17 【规则2：判断当前用户属性是否符合当前资源位投放的用户属性要求】
 */
@Component
public class UserGroupRule extends BasicRule<UserPortrait, UserPortraitRuleContext> {
  @Override
  public boolean evaluate(UserPortraitRuleContext context) {
    UserPortrait data = context.getData();
    String userGroup = data.getUserGroup();
    if (userGroup.equals(context.getBasicInfo().getUserGroup())) {
      context.setValid(true);
    } else {
      context.setValid(false);
    }
    return false;
  }

  @Override
  public void execute(UserPortraitRuleContext context) {}
}
